<template>
	<view class="notice-box w100">
		<template v-if="noticeList.list.length>0">
			<view class="notice-item w100" @click="viewNotice(item)" v-for="(item,index) in noticeList.list"
				:key="item.id">
				<text class="title w100">{{item.title}}</text>
				<view class="notice-bottom flex-row-center w100">
					<text class="time">{{item.create_time_text}}</text>
					<view class="option-box flex-row-center">
						<!-- <text class="status">已读</text> -->
						<text class="text">查看详情</text>
					</view>
				</view>
			</view>
			<view class="view-more">
				<view class="view-more" @click="getMoreList()">
					<up-loadmore :status="noticeList.status" />
				</view>
			</view>
		</template>
		<view class="not-list-view" v-else>
			<text class="text">暂时没有发布公告~</text>
		</view>
	</view>
	<up-popup :show="noticeShow" round="20rpx" closeable bgColor="#222528" mode="bottom" @close="closeShow">
		<view class="notice-content w100 flex-row-center" v-if="noticeInfo">
			<scroll-view scroll-y="true" class="scroll-Y">
				<view class="w100 flex-row-center" style="flex-direction: column;">
					<text class="title">{{noticeInfo.title}}</text>
					<view class="content w100">
						<up-parse :tagStyle="tagStyles" :content="noticeInfo.content"></up-parse>
					</view>
					<text class="time">{{noticeInfo.create_time_text}}</text>
				</view>
			</scroll-view>
		</view>
	</up-popup>
</template>

<script setup>
	const noticeList = reactive({
		status: 'loadmore',
		page: 1,
		list: []
	});
	const noticeInfo = ref(null);
	const noticeShow = ref(false);
	const closeShow = () => {
		noticeShow.value = false;
		noticeInfo.value = null;
	}
	const tagStyles = {
		p: "color:#dedede;font-size:24rpx;line-height:42rpx;",
		span: "color:#dedede;font-size:24rpx;line-height:42rpx;",
		div: "color:#dedede;font-size:24rpx;line-height:42rpx;",
		img: "max-width:700rpx;",
		image: "max-width:700rpx;",
	};
	onLoad(() => {
		getNoticeList();
	});
	onReachBottom(() => {
		getMoreList();
	})
	const getMoreList = () => {
		if (noticeList.status === 'nomore' || noticeList.status === 'loading') return;
		noticeList.status = 'loading';
		setTimeout(() => {
			getNoticeList();
		}, 600)
	}
	const getNoticeList = async () => {
		const res = await $Api.user.getNoticeList({
			page: noticeList.page,
		})
		if (res.code == '1') {
			if (res.data.list && res.data.list.length > 0) {
				noticeList.list = [...noticeList.list, ...res.data.list];
			}
			if (res.data.totalPage && res.data.totalPage > noticeList.page) {
				noticeList.status = 'loadmore';
				noticeList.page++;
			} else {
				noticeList.status = 'nomore';
			}
		} else {
			uni.$u.toast(res.msg);
		}
	}
	const viewNotice = (item) => {
		noticeInfo.value = item;
		noticeShow.value = true;
	}
</script>
<style>

</style>
<style lang="scss" scoped>
	.notice-box {
		padding: 20rpx;


		.notice-item {
			border-radius: 16rpx;
			padding: 18rpx;
			background-color: #222528;
			margin-bottom: 24rpx;


			.title {
				display: block;
				color: $title-color;
				font-size: 32rpx;
				text-overflow: ellipsis;
				white-space: nowrap;
				lines: 1;
				overflow: hidden;
			}

			.notice-bottom {
				justify-content: space-between;
				margin-top: 18rpx;

				.time {
					color: $description-color;
					font-size: 24rpx;
				}

				.option-box {
					.text {
						font-size: 24rpx;
						font-weight: 400;
						color: #7EDE9E;
						margin-right: 10rpx;
					}
				}

				.status {
					color: $description-color;
					font-size: 24rpx;
				}
			}
		}
	}

	.notice-content {
		padding: 32rpx 24rpx;
		background-color: #222528;
		border-radius: 20rpx;
		height: 60vh;
		flex-direction: column;
		align-items: center;

		.scroll-Y {
			width: 100%;
			height: 100%;
		}

		.title {
			color: $title-color;
			font-size: 32rpx;
		}

		.content {
			font-size: 28rpx;
			margin-top: 32rpx;
			color: $description-color !important;
			font-size: 24rpx !important;
		
		}

		.time {
			width: 100%;
			text-align: right;
			display: block;
			align-self: flex-end;
			color: $description-color;
			font-size: 24rpx;
			margin-top: 32rpx;
		}

	}
</style>